<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>医疗器械事件上报详细表</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
  <style>
    @page {
      width: 1200px ;
    }
    /*打印所用的css*/
    @media print {
      #button_bar {
        display: none;
      }

      #content_wrap {
        width: 1000px !important;
        /*布局的时候，为了给侧边栏留位置，给主体内容加了margin-left，现在需要去掉。*/
        margin-left: 0 !important;
        /*margin-bottom: 0 !important;*/
        /*margin-top: 0 !important;*/
        /*margin-right: 0 !important;*/
      }
    }
  </style>
</head>
<body>
<div class="layui-form-item" id="button_bar"  id="content_wrap">
  <div class="layui-input-block" style=" margin-top: 20px">
    <button type="button" class="layui-btn"  id = “back” onclick="self.location = document.referrer;">返回</button>
    <button type="button" class="layui-btn"  id="dayin">打印</button>
  </div>
</div>
<form class="layui-form" lay-filter="FormLoad">
  <!--startprint1-->
  <table border="1px" width="100%" cellpadding="0">
    <tr >
      <td colspan="4" style="text-align: center; height: 50px"> <span style=" font-size: 20px">医疗器械不良事件报告表</span> </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          报告日期：
        </td>
        <td colspan="1">
          <input type="text" name="report_date" id="report_date" placeholder="" class="layui-input" disabled>
        </td>

        <td>
          报告来源：
        </td>

        <td colspan="1">
          <input type="text" name="report_source" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          报告人：
        </td>
        <td colspan="1">
          <input type="text" name="reporter" placeholder="" class="layui-input" disabled>
        </td>

        <td>
          科室名称：
        </td>

        <td colspan="1">
          <input type="text" name="reporter_department" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <td colspan="4" style="height: 50px; text-align: center" >
        患者资料
      </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          姓名:
        </td>
        <td>
          <input type="text" name="patient_name" placeholder="" class="layui-input" disabled>
        </td>

        <td>
          年龄
        </td>

        <td>
          <input type="text" name="patient_age" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          性别：
        </td>
        <td colspan="1">

          <input type="text" name="patient_sex" placeholder="" class="layui-input" disabled>
<!--          <select name="patient_sex" lay-verify="required" disabled>-->
<!--            <option value=""></option>-->
<!--            <option value="男">男</option>-->
<!--            <option value="女">女</option>-->
<!--          </select>-->
        </td>
        <td>
        </td>
        <td>
        </td>

      </div>
    </tr>
    </tr>
    <div class="layui-form-item">
      <td>
        预期治疗疾病或作用
      </td>
      <td colspan="3">
        <textarea name="expect_treat_affect" style="height: 120px" required lay-verify="required" placeholder="请输入" class="layui-textarea" disabled></textarea>
      </td>
    </div>
    </tr>
    <tr>
      <td colspan="4" style="height: 50px; text-align: center" >
        不良事件情况
      </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1" >
          出现不良反应医疗器械品牌
        </td>
        <td colspan="1">
          <input type="text" name="apparatus_brand" placeholder="" class="layui-input" disabled>
        </td>
        <td>
          出现不良反应医疗器械名称
        </td>
        <td colspan="1">
          <input type="text" name="apparatus_name" placeholder="" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          出现不良反应医疗器械批号
        </td>
        <td colspan="1">
          <input type="text" name="apparatus_num" placeholder="" class="layui-input" disabled>
        </td>
        <td></td> <td></td>
      </div>
    </tr>
    <div class="layui-form-item">
      <td>
        事件主要陈述及表现
      </td>
      <td colspan="3">
        <textarea name="bad_event_main_declare" style="height: 120px" required lay-verify="required" placeholder="请输入" class="layui-textarea" disabled></textarea>
      </td>
    </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          事件发生日期
        </td>
        <td colspan="1">
          <input type="text" name="event_happen_time" autocomplete="off" id="event_happen_time" class="layui-input" disabled>
        </td>
        <td colspan="1">
          发生或者知悉时间
        </td>
        <td colspan="1">
          <input type="text" name="reporter_know_time" autocomplete="off" id="reporter_know_time" class="layui-input" disabled>
        </td>
      </div>
    </tr>
    <tr style="font-size: 20px">
      <div class="layui-form-item">
        <td colspan="1"> 事件后果及处理措施
        </td>
        <td colspan="3">
          <textarea name="bad_event_ending" style="height: 120px" required lay-verify="required" placeholder="请输入" class="layui-textarea" disabled></textarea>
        </td>
      </div>
    </tr>
    <tr>
      <td colspan="4">
        （外科治疗避免上述永久损伤: 可能导致机体功能机构永久性损伤： 机体功能机构永久性损伤：至少包括器械使用时间，使用目的，使用依据，使用情况，出现的不良时间情况，对受害者影响。采取的治疗措施，器械联合使用情况）
      </td>
    </tr>
  </table>
  <!--endprint1-->

</form>
</body>

<script>

  let str;
  layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
    let $ = layui.jquery;
    let form = layui.form;
    let laydate = layui.laydate;
    var layer = layui.layer;
    var router = layui.router();
    laydate.render({
      elem: '#reporter_know_time' //指定元素
      , type: 'date'
    });
    laydate.render({
      elem: '#event_happen_time' //指定元素
      , type: 'date'
    });

    // 打印固定地方
    function preview(oper) {
      if (oper < 10){
        var bdhtml=window.document.body.innerHTML;//获取当前页的html代码
        var sprnstr="<!--startprint"+oper+"-->";//设置打印开始区域
        var eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域
        var prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html

        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
        window.document.body.innerHTML=prnhtml;
        window.print();
        window.document.body.innerHTML=bdhtml;

      }
      else{
        window.print();
      }

    }
//获取打印按钮
    $("#dayin").click(function() {
      onclick=preview(1);
    })


    function getQueryVariable(variable)
    {
      let query = window.location.search.substring(1);
      let vars = query.split("&");
      for (let i=0;i<vars.length;i++) {
        let pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
      }
      return(false);
    }

    form.render();
    // 获取地址的中的值
    let form_code=getQueryVariable("form_code");
    console.log(form_code);
    $.ajax({
      url: '/look?form_code=' + form_code,
      type: 'get',
      success: function (data) {
        console.log(data);
        let jsonObj = eval('(' + data + ')'); //获得jsonObj对象
        console.log(jsonObj);
        //渲染 上报人和上报人单位
        //let json = {};
        for(let i = 0; i<jsonObj.data.length; i++) {
          //给input 框 赋值
          $('input[name= '+ jsonObj.data[i].property_en_name +']').attr("value",jsonObj.data[i].detailed_data);
          // 给 textarea赋值
          $('textarea[name= '+ jsonObj.data[i].property_en_name +']').text(jsonObj.data[i].detailed_data);
        }

        //form.val("FormLoad",json)
      }
    });

  })
</script>

</html>